package com.ruoyi.recommd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recommd.domain.RecommdPage;
import com.ruoyi.recommd.service.IRecommdPageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模版Controller
 * 
 * @author 李文保
 * @date 2025-05-26
 */
@RestController
@RequestMapping("/recommd/template")
public class RecommdPageController extends BaseController
{
    @Autowired
    private IRecommdPageService recommdPageService;

    /**
     * 查询模版列表
     */
    @PreAuthorize("@ss.hasPermi('recommd:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecommdPage recommdPage)
    {
        startPage();
        List<RecommdPage> list = recommdPageService.selectRecommdPageList(recommdPage);
        return getDataTable(list);
    }

    /**
     * 导出模版列表
     */
    @PreAuthorize("@ss.hasPermi('recommd:template:export')")
    @Log(title = "模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecommdPage recommdPage)
    {
        List<RecommdPage> list = recommdPageService.selectRecommdPageList(recommdPage);
        ExcelUtil<RecommdPage> util = new ExcelUtil<RecommdPage>(RecommdPage.class);
        util.exportExcel(response, list, "模版数据");
    }

    /**
     * 获取模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('recommd:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recommdPageService.selectRecommdPageById(id));
    }

    /**
     * 新增模版
     */
    @PreAuthorize("@ss.hasPermi('recommd:template:add')")
    @Log(title = "模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecommdPage recommdPage)
    {
        return toAjax(recommdPageService.insertRecommdPage(recommdPage));
    }

    /**
     * 修改模版
     */
    @PreAuthorize("@ss.hasPermi('recommd:template:edit')")
    @Log(title = "模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecommdPage recommdPage)
    {
        return toAjax(recommdPageService.updateRecommdPage(recommdPage));
    }

    /**
     * 删除模版
     */
    @PreAuthorize("@ss.hasPermi('recommd:template:remove')")
    @Log(title = "模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recommdPageService.deleteRecommdPageByIds(ids));
    }
}
